<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<script src="../js/common/jquery.js"></script>
<script src="../js/common/drag.js"></script>
<script src="../js/common/angular.min.js"></script>
<script type="text/javascript" src="../js/common/common.js"></script>
<script type="text/javascript" src="../js/watch.js"></script>
</head>
<body ng-app="myApp">

<div class="dqwz">
    <span>当前位置：</span>
    <span>AngularJS 监听</span>
</div>

<section>
    <div ng-controller="attributeCtrl">
        <h3>【监听一个属性】</h3>
        <form>
            <div class="form-group">
                <input  ng-model="name" />{{name}}
                <p>改变次数{{count}}</p>
            </div>
        </form>
        <!-- 查看源码开始 -->
        <div class="htmlCode">
            <span>【html源码】</span>
            <xmp ng-non-bindable>
<form>
    <div class="form-group">
        <input  ng-model="name" />{{name}}
        <p>改变次数{{count}}</p>
    </div>
</form>
            </xmp>
            <span>【js源码】</span>
            <xmp>
app.controller('attributeCtrl',function($scope){
    $scope.name = '橘子';
    $scope.count = 0;
    $scope.$watch('name', function (newValue, oldValue) {
        $scope.count++;
        if($scope.count >5){
            $scope.name = '苹果';
        }
    });
})
            </xmp>
            <span class="close"><a href="javascript:;">关闭</a></span>
        </div>
        <div class="viewCode">
            <span><a href="javascript:;"> >>查看源码</a></span>
        </div>
        <!-- 查看源码结束 -->
    </div>
    <div ng-controller="objectCtrl">
        <h3>【监听一个对象】</h3>
        <form>
            <div class="form-group">
                <input  ng-model="data.name" />{{data.name}}
                <p>改变次数{{count}}</p>
            </div>
        </form>
        <!-- 查看源码开始 -->
        <div class="htmlCode">
            <span>【html源码】</span>
            <xmp ng-non-bindable>
<form>
    <div class="form-group">
        <input  ng-model="data.name" />{{data.name}}
        <p>改变次数{{count}}</p>
    </div>
</form>
            </xmp>
            <span>【js源码】</span>
            <xmp>
app.controller('objectCtrl',function($scope){
    $scope.data = {'name':'张三'};
    $scope.count = 0;
    $scope.$watch('data', function(newValue, oldValue){
        if(newValue == oldValue){
            return false;
        }
        $scope.count++;
        if($scope.count>5){
            $scope.data.name = "李四";
        }
    },true)
})
            </xmp>
            <span class="close"><a href="javascript:;">关闭</a></span>
        </div>
        <div class="viewCode">
            <span><a href="javascript:;"> >>查看源码</a></span>
        </div>
        <!-- 查看源码结束 -->
    </div>
</section>

<div class="mask_layer">
</div>

</body>
</html>
